package com.iot.service;

import com.iot.mapper.DTwarn_levelMapper;
import com.iot.mapper.Twarn_levelMapper;
import com.iot.pojo.MTwarn_level;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class Twarn_levelServiceImpl implements  Twarn_levelService  {
    @Autowired
    private Twarn_levelMapper mapper;
    @Autowired
    private DTwarn_levelMapper dmapper;
    @Override
    public int getRecordCount(String sWhere) {
        return mapper.getRecordCount(sWhere);
    }
    @Override
    public int insert(MTwarn_level mTwarn_level) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTwarn_level.getSNAME() + "'");
        if (count > 0)
            throw new Exception("该名称已存在");
        return mapper.insert(mTwarn_level);
    }

    @Override
    public void update(MTwarn_level mTwarn_level) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTwarn_level.getSNAME() + "' AND WARN_LEVEL_ID!=" + mTwarn_level.getWARN_LEVEL_ID() + "");
        if (count > 0)
            throw new Exception("该名称已存在");
        mapper.update(mTwarn_level);
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public MTwarn_level single(Integer id) {
        return mapper.single(id);
    }

    @Override
    public List<MTwarn_level> fetch(String sWhere) {
        return mapper.fetch(sWhere);
    }

    @Override
    public List<MTwarn_level> fetchByPage(Map<String, Object> map) {

        return dmapper.fetchByPage(map);
    }


}
